package com.example.chapter09.receiver;

import android.annotation.SuppressLint;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Vibrator;
import android.util.Log;

// 定义一个标准广播的接收器
public class StandardReceiver extends BroadcastReceiver {


    public static final String STANDARD_ACTION = "com.dongnaoedu.chapter09.standard";


    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent != null && intent.getAction().equals(StandardReceiver.STANDARD_ACTION)) {
            Log.d("brand","接收到一个广播");
            //从系统服务中获取震动管理器
         @SuppressLint("ServiceCast") Vibrator vb = (Vibrator) context.getSystemService(Context.VIBRATOR_MANAGER_SERVICE);
            //命令震动器震动500ms
            vb.vibrate(500);

        }

    }
}
